<?php
/**
 * 登录控制器
 */

class LoginAction extends Action {
    public function index() {
        if (logined()) {
            $this->success('已登录', U('Index/index'));
        }

        if ($this->isPost()) {
            $this->email = $this->_param('email');
            $this->password = md5($this->_param('password'));
            $this->user = D('Member')->where(array(
                'email' => $this->email))->relation(true)->find();

            if ($this->user == null) {
                $this->error_email = '邮箱不存在';
                $this->display();
                return;
            }

            if ($this->password != $this->user['password']) {
                $this->error_password = '密码错误';
                $this->display();
                return;
            }

            $this->success('登录成功', U('Index/index'));
            $_SESSION['user'] = $this->user;
        } else {
            $this->display();
        }
    }
}
